/*
 * @Author: wuqingchun
 * @Date: 2024-05-26 10:18:14
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-05-26 10:20:40
 */
#include <iostream>
#include <vector>
#include <thread>

class NormalCounter
{
public:
    void RunTest(uint32_t uiThreadNum)
    {
        auto threadFunc = [&]()
        {
            uint32_t uiCount = 0;
            while (uiCount++ < 1000000)
            {
                m_ui64Counter++;
            }
        };

        for (uint32_t uiIndex = 0; uiIndex < uiThreadNum; uiIndex++)
        {
            m_vecThreads.push_back(std::thread(threadFunc));
        }

        for (auto& refThread : m_vecThreads)
        {
            refThread.join();
        }

        std::cout << "Counter: " << m_ui64Counter << std::endl;
    }

private:
    std::vector<std::thread> m_vecThreads;    
    uint64_t                 m_ui64Counter;
};

int main(int argc, char** argv)
{
    NormalCounter objCounter;

    if (argc < 2)
    {
        std::cout << "Usage: " << argv[0] << " thread-number" << std::endl;
        return 0;
    }

    objCounter.RunTest(atoi(argv[1]));

    return 0;
}